(function(win){
	
	//约定好象棋的大小为30px
	
	

	
	
	
	
	
	
	
	
	
	class Chess{
		info={
			id:'',
			name:'',
			camp:'',
			location:{
				x:'',
				y:''
			},
			chessType:'',
			el:null,
			type:'chess',
			
		}
		constructor(name,location,camp,chessType,id){
			this.info.name=name
			this.info.camp=camp
			this.info.chessType=chessType
			this.info.location.x=location.x
			this.info.location.y=location.y
			this.info.id=id
			this.create()
		}
		create(){
			this.info.el=document.createElement('div')
			this.info.el.className='chess'
			this.info.el.style.backgroundColor=this.info.camp
			this.info.el.style.border=`1px solid ${this.info.camp}`
			this.info.el.style.top=this.info.location.y+'px'
			this.info.el.style.left=this.info.location.x+'px'
			this.info.el.innerHTML=this.info.name
			
		}
		
		move(endDot){
			
			if(!win.rulesTypes[this.info.chessType](this,endDot))return false
		
			lastChessInfo.lastChess.lastLocation.x= this.info.location.x
			lastChessInfo.lastChess.lastLocation.y=  this.info.location.y
			lastChessInfo.lastEndDot=endDot
			lastChessInfo.lastChess.chess=this
			
			
			if(endDot.info.type=='dot'){
				this.info.location.x=endDot.info.location.x-10
				this.info.location.y=endDot.info.location.y-10
				
			}else{
				var deleteChessIndex = chessList.findIndex((item)=>{
					return item.instance.info.id == endDot.info.id
				})
				chessList.splice(deleteChessIndex,1)
				document.getElementById('board').removeChild(endDot.info.el)
				
				this.info.location.x=endDot.info.location.x
				this.info.location.y=endDot.info.location.y						
			}
			
		
			
			
			this.info.el.style.top=this.info.location.y+'px'
			this.info.el.style.left=this.info.location.x+'px'
			
			
			
			if(endDot.info.type=='chess'&& endDot.info.chessType=='boss'){
				alert(`'${this.info.camp}方 胜利!'`)
			}
			return true
		}
		
	}
	
	
	
	
	
	
	win.initChess=function({chessType,location,name,camp,id}){
		
		const chessInstance= new Chess(name,location,camp,chessType,id)
		
		return chessInstance
	}


	
	
	
	
})(window);